<?php
require_once 'modules/service/commonService.php';

class CategorysService extends CommonService {

    /**
     * @desc 分类服务层
     * @author liuhui 
     * @version 2009-7-3
     */
    
    /**
     * @desc 增加一个分类
     * @param array $fields array(title,description,privacy,picture,displayorder)
     */
    public function add (array $fields) {
        $fields = $this->checkFields($fields, Consts::FIELDS_CATEGORYS());
        if (!$fields) {
            return null;
        }
        $fields[Consts::F_CREATE_AT] = time();
        $fields[Consts::F_UPDATE_AT] = time();
        return $this->getDaoFactory()->getCategorysDao()->add($fields);
    }

    public function update (array $fields, $category_id) {
        $fields = $this->checkFields($fields, Consts::FIELDS_CATEGORYS());
        if (!$fields || $this->filterParam($category_id) < 1) {
            return null;
        }
        $fields[Consts::F_UPDATE_AT] = time();
        return $this->getDaoFactory()->getCategorysDao()->update($fields, $category_id);
    }

    public function get ($category_id) {
        if ($this->filterParam($category_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getCategorysDao()->get($category_id);
    }

    public function delete ($category_id) {
        if ($this->filterParam($category_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getCategorysDao()->delete($category_id);
    }

    public function gets ($offset = 0, $limit = 20) {
        return $this->getDaoFactory()->getCategorysDao()->gets($offset, $limit);
    }

    public function count () {
        return $this->getDaoFactory()->getCategorysDao()->count();
    }

}
